package pruebas;

import junit.framework.TestCase;
import negModel.*;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;


public class SuperficieTest extends TestCase {
	
	Superficie s;
	Element e;
	
	protected void setUp() throws Exception {
		super.setUp();
		
		s= new Superficie(0.4,"Hielo");
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	    DocumentBuilder loader = factory.newDocumentBuilder();
	    Document doc = loader.newDocument();
				
		e= doc.createElement("superficie");
		
		e.setAttribute("coef", ""+ s.getCoeficiente());
		e.setAttribute("nombre", s.getNombre());
		
	}
		
	public void testCoeficiente(){
		assertEquals(0.4,s.getCoeficiente(),0.0);
		
	}
	
	public void testNombre(){
		assertEquals("Nombre","Hielo",s.getNombre());
		
	}
	
	public void testClima () {
		
		Superficie s2=new Superficie(e);
		
		assertEquals(s2.getCoeficiente(),Double.parseDouble(e.getAttribute("coef")),0.0);
		assertEquals(s2.getNombre(),e.getAttribute("nombre"));
		
	}
	
	public void testToXml () throws Exception {
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	    DocumentBuilder loader = factory.newDocumentBuilder();
	    Document doc = loader.newDocument();
		
		e=s.toXml(doc);
		
		assertEquals(Double.parseDouble(e.getAttribute("coef")),s.getCoeficiente(),0.0);
		assertEquals(e.getAttribute("nombre"),s.getNombre());
	}


}
